﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;


namespace IHISCETeim.DAL
{
    public class WOWORTaskDAL : SyncSAPDAL
    {
        /// <summary>
        /// 获取可使用的未清生产订单
        /// </summary>
        /// <param name="ItemCode"></param>
        /// <returns></returns>
        public static DataTable GetTask(string ItemCode)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WOWORTask_GetTask", ItemCode, DataSource, UserID, Password, InitialCatalog);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }


        /// <summary>
        /// 添加生产任务
        ///处理方法:
        ///将不同生产订单相同物料号的合并起来,不区分工位
        /// </summary>       
        /// <returns></returns>
        public static int AddWoroTask(string RealName,string Pname,string docnums,string SendQtys)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WOWORTask_AddWoroTask", RealName,Pname,docnums,SendQtys, DataSource, UserID, Password, InitialCatalog);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        /// <summary>
        /// 检测生产作业项目是否发布过
        /// </summary>
        /// <param name="Pname"></param>
        /// <returns></returns>
        public static int CheckOWORTaskByPName(string Pname)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WOWORTask_CheckOWORTaskByPName",  Pname);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }

        /// <summary>
        /// 获取发料列表
        /// </summary>
        /// <param name="SQLWHERE"></param>
        /// <returns></returns>
        public static DataTable GetNeedSendItm(string SQLWHERE)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WPrdctShipLst_GetNeedSendItm", SQLWHERE);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }

        /// <summary>
        /// 发料操作
        /// </summary>
        /// <param name="IDs"></param>
        /// <param name="NowSendQtys"></param>
        /// <returns></returns>
        public static int SendPrdctShip(string IDs, string NowSendQtys, string OperateUser)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WPrdctShipLst_SendPrdctShip", OperateUser,IDs, NowSendQtys);
            return Convert.ToInt32( DB.ExecuteScalar(dbCommand));
        }

        /// <summary>
        /// 获取需要发料的项目,项目需为未完成
        /// </summary>
        /// <param name="IDs"></param>
        /// <param name="NowSendQtys"></param>
        /// <returns></returns>
        public static DataTable GetNeedSendProject()
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("WOWORTask_GetNeedSendProject");
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }
    }
}
